package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.BusinessLine;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BussinessDept;
import com.ruoyi.system.service.IBussinessDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事业部Controller
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@RestController
@RequestMapping("/system/bussinessdept")
public class BussinessDeptController extends BaseController {
    @Autowired
    private IBussinessDeptService bussinessDeptService;


    @PreAuthorize("@ss.hasPermi('system:bussinessdept:list')")
    @GetMapping("/getAll")
    public AjaxResult getAll() {
        List<BussinessDept> list = bussinessDeptService.list();
        return AjaxResult.success(list);
    }

    /**
     * 查询事业部列表
     */
    @PreAuthorize("@ss.hasPermi('system:bussinessdept:list')")
    @GetMapping("/list")
    public TableDataInfo list(BussinessDept bussinessDept) {
        startPage();
        List<BussinessDept> list = bussinessDeptService.selectBussinessDeptList(bussinessDept);
        return getDataTable(list);
    }

    /**
     * 导出事业部列表
     */
    @PreAuthorize("@ss.hasPermi('system:bussinessdept:export')")
    @Log(title = "事业部", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BussinessDept bussinessDept) {
        List<BussinessDept> list = bussinessDeptService.selectBussinessDeptList(bussinessDept);
        ExcelUtil<BussinessDept> util = new ExcelUtil<BussinessDept>(BussinessDept.class);
        util.exportExcel(response, list, "事业部数据");
    }

    /**
     * 获取事业部详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bussinessdept:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bussinessDeptService.selectBussinessDeptById(id));
    }

    /**
     * 新增事业部
     */
    @PreAuthorize("@ss.hasPermi('system:bussinessdept:add')")
    @Log(title = "事业部", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BussinessDept bussinessDept) {
        return toAjax(bussinessDeptService.insertBussinessDept(bussinessDept));
    }

    /**
     * 修改事业部
     */
    @PreAuthorize("@ss.hasPermi('system:bussinessdept:edit')")
    @Log(title = "事业部", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BussinessDept bussinessDept) {
        return toAjax(bussinessDeptService.updateBussinessDept(bussinessDept));
    }

    /**
     * 删除事业部
     */
    @PreAuthorize("@ss.hasPermi('system:bussinessdept:remove')")
    @Log(title = "事业部", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bussinessDeptService.deleteBussinessDeptByIds(ids));
    }
}
